﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using RibbonEditor.AppCode;

namespace RibbonEditor.CommandUIDefinitionClasses
{
    public class CheckBox : ICommandUIDefinition, IControlsChild, IXmlBuildable
    {
        public string Alt { get; set; }
        public string Command { get; set; }
        public string Id { get; set; }
        public string LabelText { get; set; }
        public string MenuItemId { get; set; }
        public string QueryCommand { get; set; }
        public int? Sequence { get; set; }
        public string TemplateAlias { get; set; }
        public string ToolTipDescription { get; set; }
        public string ToolTipHelpKeyWord { get; set; }
        public string ToolTipImage32by32 { get; set; }
        public string ToolTipImage32by32Class { get; set; }
        public int? ToolTipImage32by32Left { get; set; }
        public int? ToolTipImage32by32Top { get; set; }
        public string ToolTipShortcutKey { get; set; }
        public string ToolTipTitle { get; set; }

        public CheckBox()
        {}

        public CheckBox(XmlNode node): this()
        {
            try
            {
                this.Alt = (string)XmlHelper.GetAttribute(node, "Alt");
                this.Command = (string)XmlHelper.GetAttribute(node, "Command");
                this.Id = (string)XmlHelper.GetAttribute(node, "Id");
                this.LabelText = (string)XmlHelper.GetAttribute(node, "LabelText");
                this.MenuItemId = (string)XmlHelper.GetAttribute(node, "MenuItemId");
                this.QueryCommand = (string)XmlHelper.GetAttribute(node, "QueryCommand");
                this.Sequence = XmlHelper.GetNullableIntAttribute(node, "Sequence");
                this.TemplateAlias = (string)XmlHelper.GetAttribute(node, "TemplateAlias");
                this.ToolTipDescription = (string)XmlHelper.GetAttribute(node, "ToolTipDescription");
                this.ToolTipHelpKeyWord = (string)XmlHelper.GetAttribute(node, "ToolTipHelpKeyWord");
                this.ToolTipImage32by32 = (string)XmlHelper.GetAttribute(node, "ToolTipImage32by32");
                this.ToolTipImage32by32Class = (string)XmlHelper.GetAttribute(node, "ToolTipImage32by32Class");
                this.ToolTipImage32by32Left = XmlHelper.GetNullableIntAttribute(node, "ToolTipImage32by32Left");
                this.ToolTipImage32by32Top = XmlHelper.GetNullableIntAttribute(node, "ToolTipImage32by32Top");
                this.ToolTipShortcutKey = (string)XmlHelper.GetAttribute(node, "ToolTipShortcutKey");
                this.ToolTipTitle = (string)XmlHelper.GetAttribute(node, "ToolTipTitle");
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void AddNode(XmlNode customActionNode)
        {
            try
            {
                XmlNode buttonNode = XmlHelper.AddNode(customActionNode, "CheckBox");
                XmlHelper.AddAttribute(buttonNode, "Alt", this.Alt);
                XmlHelper.AddAttribute(buttonNode, "Command", this.Command);
                XmlHelper.AddAttribute(buttonNode, "Id", this.Id);
                XmlHelper.AddAttribute(buttonNode, "LabelText", this.LabelText);
                XmlHelper.AddAttribute(buttonNode, "MenuItemId", this.MenuItemId);
                XmlHelper.AddAttribute(buttonNode, "QueryCommand", this.QueryCommand);
                XmlHelper.AddAttribute(buttonNode, "Sequence", this.Sequence);
                XmlHelper.AddAttribute(buttonNode, "TemplateAlias", this.TemplateAlias);
                XmlHelper.AddAttribute(buttonNode, "ToolTipDescription", this.ToolTipDescription);
                XmlHelper.AddAttribute(buttonNode, "ToolTipHelpKeyWord", this.ToolTipHelpKeyWord);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32", this.ToolTipImage32by32);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32Class", this.ToolTipImage32by32Class);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32Left", this.ToolTipImage32by32Left);
                XmlHelper.AddAttribute(buttonNode, "ToolTipImage32by32Top", this.ToolTipImage32by32Top);
                XmlHelper.AddAttribute(buttonNode, "ToolTipShortcutKey", this.ToolTipShortcutKey);
                XmlHelper.AddAttribute(buttonNode, "ToolTipTitle", this.ToolTipTitle);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void BuildTreeViewElement(TreeNode parentNode)
        {
            try
            {
                TreeNode node = new TreeNode("CheckBox");
                node.Tag = this;
                node.ContextMenuStrip = ContextMenuStripHelper.BuildUICommandDefContextMenuStrip(node, null, true);

                parentNode.Nodes.Add(node);
            }
            catch (Exception error)
            {
                MessageBox.Show("An error occured: " + error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
